#include<iostream>
#include<functional>
#include<queue>
#include<condition_variable>
#include<mutex>
#include<thread>
#include<unistd.h>
using namespace std;
using callback=function<void(void*arg)>;   //任务回调函数
struct Task{
   Task(callback f1,void*arg1);
   Task();
   callback f;
   void *arg;
};
class ThreadPool{
public:
   ThreadPool(int threadnum,int threadpoolmaxnum=3999);
   ThreadPool(ThreadPool&&pa)=delete;
   ~ThreadPool();
   void StartThreadPool(int ThreadNum);        //启动线程池
   
   void addTask(Task t);
   void addTask(callback f,void*arg);

   void ThreadPooljoin();                       //阻塞
private:
   static void ThreadPoolFuntion(ThreadPool*pool);
public:
    static void ManageThread(ThreadPool*pool);  //管理者线程
public:
    mutex mtx;
    condition_variable cond;
    bool isstart;      //线程池是否启动   true 启动  false 关闭
    //任务队列
    queue<Task>task_queue;

    //实现工作数组操作的同步
    mutex worker_mtx;                 
    condition_variable worker_cond;
    vector<thread*>workerthread;


    //管理线程池
    mutex management_mtx;   
    int StartThreadNum;        //起始线程数
    int LeisureThreadNum;      //当前空闲线程数
    int BusyThreadNum;         //忙碌的线程数量   
    int GeneralThreadNum;      //总的线程数 
    int ThreadPoolMaxNum;      //线程池最大线程数  
};



